/*
	This file is part of the JKTest
    Copyright (C) 2008 Royce Y. Feng <ryfeng@gmail.com>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License version 3
    as published by the Free Software Foundation. You may not use, modify
    or distribute this program under any other version of the
    GNU Affero General Public License.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package GUIExtras;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JMenuItem;

/**
 *
 * Class to add an ActionListener to JMenuItem.
 * 
 * @author Royce Feng
 */
public class JKMenuItem extends JMenuItem implements ActionListener {

    private MainMenuBar parent;
    
    /**
     * 
     * Main Constructor for JKMenuItem. Creates a new instance of JKMenuItem and
     * adds an actionListener to it. Also references the parent class for action
     * events.
     * 
     * @param _parent The Parent Class
     */
    public JKMenuItem(MainMenuBar _parent, String menuText) {
        super(menuText);
        // Ew, this code looks hideous
        this.addActionListener(this);
        parent = _parent;
    }
    
    /**
     * 
     * ActionListener method. Tells the Parent that an item has been selected
     * 
     * @param e
     */
    public void actionPerformed( ActionEvent e ) {
        JKMenuItem source = (JKMenuItem)e.getSource();    
        String sourceText = source.getText();
        parent.MenuItemClicked(sourceText);
    }
    
}
